package com.superman.serviceImpl;



import java.util.List;

import com.superman.dao.ProductDao;
import com.superman.domain.PageBean;
import com.superman.domain.Product;
import com.superman.service.ProductService;

public class ProductServiceImpl implements ProductService {
	private ProductDao productDao = new ProductDaoImpl();

	@Override
	public PageBean page(int pageNum) {
		//获取总记录数
		int total = productDao.count();
		//单页记录数
		int size = 6;
		//计算总页数
		int end = (total%size==0)?(total/size):(total/size)+1;
		//获取起始位置
		int startIndex = (pageNum-1)*size;
		List<Product> data = productDao.page(startIndex,size);
		PageBean pageBean = new PageBean();
		pageBean.setTotal(total);
		pageBean.setSize(size);
		pageBean.setEnd(end);
		pageBean.setData(data);
		pageBean.setPageNum(pageNum);
		return pageBean;
	}

	@Override
	public List<Product> findAllProduct() {
		return productDao.findAllProduct();
		
	}

	@Override
	public Product update(String pid) {
		return productDao.update(pid);
	}

	@Override
	public void updateProduct(Product p) {
		productDao.updateProduct(p);
	}

	@Override
	public void deleteProduct(String pid) {
		productDao.deleteProduct(pid);
	}




}
